package com.micromall.controller;

import java.util.List;
import java.util.Date;

import com.micromall.common.utils.DateUtil;
import com.micromall.common.utils.Dict;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.micromall.common.base.BaseController;
import com.micromall.common.utils.PageInfo;
import com.micromall.common.utils.DateUtils;
import com.micromall.model.BusiProdCategory;
import com.micromall.service.IBusiProdCategoryService;

/**
 * <p>
 * 产品类别中间表  前端控制器
 * </p>
 * @author Dante Fung
 * @since 2017-07-26
 */
@Controller
@RequestMapping("/busiProdCategory")
public class BusiProdCategoryController extends BaseController {
    
    @Autowired private IBusiProdCategoryService busiProdCategoryService;
    
    @GetMapping("/manager")
    public String manager() {
        return "admin/busiProdCategory/busiProdCategoryList";
    }


    @PostMapping("/dataGrid")
    @ResponseBody
    public PageInfo dataGrid(BusiProdCategory busiProdCategory, Integer page, Integer rows, String sort,String order) {
        EntityWrapper<BusiProdCategory> ew = new EntityWrapper<BusiProdCategory>();
        ew.setEntity(busiProdCategory);
        Page<BusiProdCategory> pages = getPage(page, rows, sort, order);
        pages = busiProdCategoryService.selectPage(pages,ew);
        return pageToPageInfo(pages);
    }
    
    /**
     * 添加页面
     * @return
     */
    @GetMapping("/addPage")
    public String addPage() {
        return "admin/busiProdCategory/busiProdCategoryAdd";
    }

    /**
     * 添加
     * @param 
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public Object add(BusiProdCategory busiProdCategory) {
        boolean b = busiProdCategoryService.insert(busiProdCategory);
        if (b) {
            return renderSuccess("添加成功！");
        } else {
            return renderError("添加失败！");
        }
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @PostMapping("/delete")
    @ResponseBody
    public Object delete(String id) {
        BusiProdCategory busiProdCategory = new BusiProdCategory();
        busiProdCategory.setId(id);
        boolean b = busiProdCategoryService.updateById(busiProdCategory);
        if (b) {
            return renderSuccess("删除成功！");
        } else {
            return renderError("删除失败！");
        }
    }

    /**
     * 编辑
     * @param model
     * @param id
     * @return
     */
    @GetMapping("/editPage")
    public String editPage(Model model, Long id) {
        BusiProdCategory busiProdCategory = busiProdCategoryService.selectById(id);
        model.addAttribute("busiProdCategory", busiProdCategory);
        return "admin/busiProdCategory/busiProdCategoryEdit";
    }

    /**
     * 编辑
     * @param 
     * @return
     */
    @RequestMapping("/edit")
    @ResponseBody
    public Object edit(BusiProdCategory busiProdCategory) {
        boolean b = busiProdCategoryService.updateById(busiProdCategory);
        if (b) {
            return renderSuccess("编辑成功！");
        } else {
            return renderError("编辑失败！");
        }
    }
    
}
